Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System
Imports System.Web
Imports System.ComponentModel.Design
Imports System.Reflection
Imports System.Web.HttpContext
Imports System.Collections
Imports MDP.Framework.Componentes

Public Class LinkCargaTemplateField
    Implements ITemplate

    Private Page As Object
    Private m_colType As ListItemType
    Private m_sColumnName As String = String.Empty
    Private m_sColumnName1 As String = String.Empty
    Private m_sColumnName2 As String = String.Empty

    Private m_sPropertyName1 As String = String.Empty
    Private m_sPropertyName2 As String = String.Empty
    Private m_sPropertyName3 As String = String.Empty

    Private m_sEditColumnName As String = String.Empty
    Private m_sTextoFixo As String = String.Empty
    Private m_URL As String
    Private m_sColumnHeader As String
    Private m_CssClass As String = String.Empty
    Private m_Width As Integer = 0
    Private m_AlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private m_AlinhametoVertical As VerticalAlign = VerticalAlign.Middle
    Private m_FormatoApresentacao As String = String.Empty
    Private m_Obrigatorio As Boolean = False
    Private bolPermiteEdicao As Boolean = True
    Private m_ListaOpcoes As String = ""


    Public ReadOnly Property NomeColuna() As String
        Get
            Return Me.m_sColumnName
        End Get
    End Property

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Try

            Select Case m_colType
                Case ListItemType.Footer

                Case ListItemType.Header

                    Dim objLabel As New Label
                    With objLabel
                        .Text = Me.m_sColumnHeader
                    End With

                    If m_CssClass <> String.Empty Then
                        objLabel.CssClass = m_CssClass
                    End If


                    If m_Width > 0 Then
                        objLabel.Width = m_Width
                    End If

                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)

                    container.Controls.Add(objLabel)

                Case ListItemType.Item, ListItemType.AlternatingItem

                    Dim objLink As New WebControls.HyperLink
                    'With objLink
                    ' .ID = "hp" & m_sColumnName
                    ' End With


                    If m_CssClass <> String.Empty Then
                        objLink.CssClass = m_CssClass
                    End If


                    If m_Width > 0 Then
                        objLink.Width = m_Width
                    End If

                    AddHandler container.DataBinding, AddressOf Item_DataBinding

                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                    container.Controls.Add(objLink)

                Case ListItemType.EditItem

                    Dim strNomeColuna As String = Me.m_sColumnName

                    If Me.m_sEditColumnName.Trim <> String.Empty Then
                        strNomeColuna = m_sEditColumnName
                    End If

                    If bolPermiteEdicao Then

                        Dim objTextBox As New TextBoxCarga
                        objTextBox.ID = "" & strNomeColuna

                        objTextBox.Obrigatorio = Me.m_Obrigatorio

                        If m_CssClass <> String.Empty Then
                            objTextBox.CssClass = m_CssClass
                        End If

                        container.Controls.Add(objTextBox)

                    Else

                        Dim objLink As New WebControls.HyperLink


                        If m_CssClass <> String.Empty Then
                            objLink.CssClass = m_CssClass
                        End If


                        If m_Width > 0 Then
                            objLink.Width = m_Width
                        End If

                        container.Controls.Add(objLink)


                    End If

                    AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)


                Case ListItemType.Pager

                Case ListItemType.SelectedItem

                Case ListItemType.Separator


            End Select

        Catch ex As Exception

        End Try
    End Sub

    Private Sub CarregarValorLink(ByVal FieldCell As DataControlFieldCell)


        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As Object = ""

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

            item1Value = DataBinder.Eval(ri.DataItem, Me.m_sColumnName)
        End If

        Dim lnk As HyperLink = FieldCell.Controls(0)

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical

        If Me.m_sTextoFixo.Trim = String.Empty Then
            If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

                If Me.m_ListaOpcoes.Split(";").Length > 1 Then

                    For Each strItem As String In Me.m_ListaOpcoes.Split(";")

                        Dim arrItem() As String
                        arrItem = strItem.Split(",")
                        If arrItem.Length = 2 Then

                            If arrItem(0) = item1Value Then
                                lnk.Text = arrItem(1)
                                Exit For
                            End If

                        End If

                    Next

                Else

                    lnk.Text = Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao)

                End If

            End If

        Else
            lnk.Text = Me.m_sTextoFixo
        End If

        lnk.NavigateUrl = Me.m_URL.Replace("{0}", Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao))

        Dim colValue1 As String = ""
        Dim colValue2 As String = ""

        If Me.m_sColumnName1.Trim <> String.Empty Then
            If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName1)) Then
                colValue1 = DataBinder.Eval(ri.DataItem, Me.m_sColumnName1)
                lnk.NavigateUrl = lnk.NavigateUrl.Replace("{1}", colValue1)
            End If
        End If

        If Me.m_sColumnName2.Trim <> String.Empty Then
            If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName2)) Then
                colValue2 = DataBinder.Eval(ri.DataItem, Me.m_sColumnName2)
                lnk.NavigateUrl = lnk.NavigateUrl.Replace("{2}", colValue2)
            End If
        End If

        Dim propValue1 As String = ""
        Dim propValue2 As String = ""
        Dim propValue3 As String = ""

        If Me.m_sPropertyName1.Trim <> String.Empty Then


            If TypeOf Me.Page Is Componentes.Page Then

                propValue1 = CType(Me.Page, Componentes.Page).CarregarValorControle(m_sPropertyName1)

            End If

            lnk.NavigateUrl = lnk.NavigateUrl.Replace("{P1}", propValue1)

        End If

        If Me.m_sPropertyName2.Trim <> String.Empty Then


            If TypeOf Me.Page Is Componentes.Page Then

                propValue2 = CType(Me.Page, Componentes.Page).CarregarValorControle(m_sPropertyName2)

            End If

            lnk.NavigateUrl = lnk.NavigateUrl.Replace("{P2}", propValue2)

        End If

        If Me.m_sPropertyName3.Trim <> String.Empty Then


            If TypeOf Me.Page Is Componentes.Page Then

                propValue3 = CType(Me.Page, Componentes.Page).CarregarValorControle(m_sPropertyName3)

            End If

            lnk.NavigateUrl = lnk.NavigateUrl.Replace("{P3}", propValue3)

        End If


        If TypeOf ri.NamingContainer.NamingContainer Is GridBusca Then

            Dim gvBusca As GridBusca
            gvBusca = ri.NamingContainer.NamingContainer

            If gvBusca.ControlesDestinos.Count > 0 Then
                For Each C As Componentes.ItemControle In gvBusca.ControlesDestinos

                    C.Valor = DataBinder.Eval(ri.DataItem, C.NomeColunaResultado)

                Next

                lnk.NavigateUrl = gvBusca.ControlesDestinos.ScriptLinkBusca

            End If

        End If
    End Sub

    Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        '        Dim FieldCell As DataControlFieldCell = sender

        CarregarValorLink(sender)

    End Sub

    Private Sub EditItem_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As String = String.Empty

        Dim strNomeColuna As String = Me.m_sColumnName

        If Me.m_sEditColumnName.Trim <> String.Empty Then
            strNomeColuna = m_sEditColumnName
        End If

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, strNomeColuna)) Then
            item1Value = DataBinder.Eval(ri.DataItem, strNomeColuna)
        End If

        If Me.bolPermiteEdicao Then
            Dim txt As TextBoxCarga = FieldCell.Controls(0)

            txt.Enabled = True
            txt.Text = item1Value

            If ri.Cells.GetCellIndex(FieldCell) = 0 Then

                CType(FieldCell.Page, Mdp.Framework.Componentes.Page).SetFocus(txt)

            End If

        Else


            CarregarValorLink(sender)

            Dim lnk As HyperLink = FieldCell.Controls(0)

            lnk.Enabled = False


        End If




    End Sub

    Public Sub New(ByRef Pg As Object, _
                   ByVal objType As ListItemType, ByVal sColumnHeader As String, _
                   ByVal sColumnName As String, ByVal sColumnName1 As String, ByVal sColumnName2 As String, ByVal sEditColumnName As String, ByVal sURL As String, ByVal iWidth As Integer, _
                   ByVal sCssClass As String, ByVal haAlinhamentoHorizontal As HorizontalAlign, _
                   ByVal vaAlinhamentoVertical As VerticalAlign, _
                   ByVal sFormatoApresentacao As String, ByVal bolObrigatorio As Boolean, _
                   ByVal sTextoFixo As String, ByVal sPropertyName1 As String, ByVal sPropertyName2 As String, ByVal sPropertyName3 As String, ByVal bolPermiteEdicao As Boolean, _
                   Optional ByVal strListaOpcoes As String = "")

        Me.Page = Pg

        m_colType = objType
        m_sColumnHeader = sColumnHeader
        m_sColumnName = sColumnName
        m_sColumnName1 = sColumnName1
        m_sColumnName2 = sColumnName2

        m_sPropertyName1 = sPropertyName1
        m_sPropertyName2 = sPropertyName2
        m_sPropertyName3 = sPropertyName3

        m_sEditColumnName = sEditColumnName
        m_URL = sURL
        m_CssClass = sCssClass
        m_Width = iWidth
        Me.m_AlinhamentoHorizontal = haAlinhamentoHorizontal
        Me.m_AlinhametoVertical = vaAlinhamentoVertical
        Me.m_FormatoApresentacao = sFormatoApresentacao
        Me.m_Obrigatorio = bolObrigatorio
        Me.m_sTextoFixo = sTextoFixo
        Me.bolPermiteEdicao = bolPermiteEdicao
        Me.m_ListaOpcoes = strListaOpcoes

    End Sub
End Class

Public Class TextBoxCargaTemplateField
    Implements ITemplate

    Private m_colType As ListItemType
    Private m_sColumnName As String
    Private m_sEditColumnName As String = String.Empty
    Private m_sColumnHeader As String
    Private m_Width As Integer = 0
    Private m_CssClass As String = String.Empty
    Private m_TipoValor As eTipoValor = eTipoValor.Texto
    Private m_TamanhoMaximo As Integer
    Private m_AlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private m_AlinhametoVertical As VerticalAlign = VerticalAlign.Middle
    Private m_FormatoApresentacao As String
    Private m_Obrigatorio As Boolean = True
    Private m_MascaraInput As String = String.Empty
    Private m_ValorDefault As String = String.Empty
    Private m_AtualizacaoEmMassa As Boolean = False
    Private m_HabilitarBusca As Boolean = False
    Private m_QuantidadeLinhas As Long = 1
    Private m_ListaOpcoes As String = ""
    Private m_bBotaoBusca As ButtonBuscaCarga

    Public ReadOnly Property NomeColuna() As String
        Get
            Return Me.m_sColumnName
        End Get
    End Property

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Try

            Select Case m_colType

                Case ListItemType.Footer

                    Dim objLabel As New Label

                    With objLabel
                        .ID = "lblTotal" & m_sColumnName
                    End With

                    objLabel.Font.Bold = True


                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)


                Case ListItemType.Header

                    Dim objLabel As New Label
                    With objLabel
                        .Text = Me.m_sColumnHeader
                    End With


                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)


                Case ListItemType.Item, ListItemType.AlternatingItem

                    If Not Me.m_AtualizacaoEmMassa Then

                        Dim objLabel As New Label

                        With objLabel
                            .ID = "lbl" & m_sColumnName
                        End With


                        CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                        AddHandler container.DataBinding, AddressOf Item_DataBinding

                        container.Controls.Add(objLabel)

                    Else


                        Dim strNomeColuna As String = Me.m_sColumnName

                        If Me.m_sEditColumnName.Trim <> String.Empty Then
                            strNomeColuna = m_sEditColumnName
                        End If

                        Dim objTextBox As New TextBoxCarga
                        objTextBox.ID = "" & strNomeColuna

                        objTextBox.Obrigatorio = m_Obrigatorio

                        If Me.m_QuantidadeLinhas > 1 Then
                            objTextBox.TextMode = TextBoxMode.MultiLine
                            objTextBox.Rows = Me.m_QuantidadeLinhas
                        End If

                        objTextBox.TipoValor = Me.m_TipoValor
                        objTextBox.MaxLength = m_TamanhoMaximo
                        objTextBox.MascaraInput = Me.m_MascaraInput
                        objTextBox.CssClass = m_CssClass

                        CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                        objTextBox.WidthCelula = Unit.Pixel(Me.m_Width)

                        objTextBox.Width = Unit.Percentage(85)

                        AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                        container.Controls.Add(objTextBox)

                    End If

                Case ListItemType.EditItem

                    Dim strNomeColuna As String = Me.m_sColumnName

                    If Me.m_sEditColumnName.Trim <> String.Empty Then
                        strNomeColuna = m_sEditColumnName
                    End If

                    Dim objTextBox As New TextBoxCarga
                    objTextBox.ID = "" & strNomeColuna


                    objTextBox.Obrigatorio = m_Obrigatorio

                    If Me.m_QuantidadeLinhas > 1 Then
                        objTextBox.TextMode = TextBoxMode.MultiLine
                        objTextBox.Rows = Me.m_QuantidadeLinhas
                    End If

                    objTextBox.TipoValor = Me.m_TipoValor
                    objTextBox.MaxLength = m_TamanhoMaximo
                    objTextBox.MascaraInput = Me.m_MascaraInput
                    objTextBox.CssClass = m_CssClass


                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                    objTextBox.WidthCelula = Unit.Pixel(Me.m_Width)

                    objTextBox.Width = Unit.Percentage(85)

                    AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                    If Me.m_HabilitarBusca Then
                        With Me.m_bBotaoBusca
                            .HabilitarSomenteEmEdicao = True
                        End With
                        Dim t As New HtmlControls.HtmlTable
                        Dim r As New HtmlControls.HtmlTableRow
                        Dim c1 As New HtmlControls.HtmlTableCell
                        Dim c2 As New HtmlControls.HtmlTableCell

                        c1.Controls.Add(objTextBox)
                        c2.VAlign = "top"
                        c2.Controls.Add(m_bBotaoBusca)

                        t.CellPadding = 0
                        t.CellSpacing = 0

                        r.Cells.Add(c1)
                        r.Cells.Add(c2)
                        t.Rows.Add(r)

                        container.Controls.Add(t)

                    Else
                        container.Controls.Add(objTextBox)

                    End If



                Case ListItemType.Pager

                Case ListItemType.SelectedItem

                Case ListItemType.Separator


            End Select

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)


        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As Object

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

            item1Value = DataBinder.Eval(ri.DataItem, Me.m_sColumnName)

            Dim lbl As Label = FieldCell.Controls(0)

            If Me.m_ListaOpcoes.Split(";").Length > 1 Then

                For Each strItem As String In Me.m_ListaOpcoes.Split(";")

                    Dim arrItem() As String
                    arrItem = strItem.Split(",")
                    If arrItem.Length = 2 Then

                        If arrItem(0) = item1Value Then
                            lbl.Text = arrItem(1)
                            Exit For
                        End If

                    End If

                Next

            Else

                lbl.Text = Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao)

            End If


        End If

    End Sub

    Private Sub EditItem_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As String = String.Empty

        Dim strNomeColuna As String = Me.m_sColumnName

        If Me.m_sEditColumnName.Trim <> String.Empty Then
            strNomeColuna = m_sEditColumnName
        End If

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, strNomeColuna)) Then
            item1Value = DataBinder.Eval(ri.DataItem, strNomeColuna)

        End If
        Dim txt As TextBoxCarga
        If TypeOf FieldCell.Controls(0) Is HtmlControls.HtmlTable Then
            txt = CType(FieldCell.Controls(0), HtmlControls.HtmlTable).Rows(0).Cells(0).Controls(0)
            txt.Width = Unit.Percentage(90)
        Else
            txt = FieldCell.Controls(0)
        End If

        txt.Enabled = True
        txt.Text = item1Value

        If ri.Cells.GetCellIndex(FieldCell) = 0 Then

            CType(FieldCell.Page, Mdp.Framework.Componentes.Page).SetFocus(txt)

        End If

    End Sub

    Public Sub New(ByVal objType As ListItemType, ByVal sColumnHeader As String, _
                   ByVal sColumnName As String, ByVal sEditColumnName As String, ByVal intTipoValor As eTipoValor, _
                   ByVal numTamanhoMaximo As Integer, _
                   ByVal iWidth As Integer, ByVal sCssClass As String, _
                   ByVal haAlinhamentoHorizontal As HorizontalAlign, _
                   ByVal vaAlinhamentoVertical As VerticalAlign, _
                   ByVal sFormatoApresentacao As String, ByVal sMascaraInput As String, _
                   ByVal bolObrigatorio As Boolean, ByVal strValorDefault As String, _
                   ByVal lngQuantidadeLinhas As Long, _
                   Optional ByVal bolAtualizacaoEmMassa As Boolean = False, _
                   Optional ByVal strListaOpcoes As String = "", _
    Optional ByVal blnHabilitarBusca As Boolean = False, _
 Optional ByVal btbBotaoBusca As Object = "")

        m_colType = objType
        m_sColumnHeader = sColumnHeader
        m_sColumnName = sColumnName
        m_sEditColumnName = sEditColumnName
        m_Width = iWidth
        m_CssClass = sCssClass
        m_TipoValor = intTipoValor
        m_TamanhoMaximo = numTamanhoMaximo
        Me.m_AlinhamentoHorizontal = haAlinhamentoHorizontal
        Me.m_AlinhametoVertical = vaAlinhamentoVertical
        Me.m_FormatoApresentacao = sFormatoApresentacao
        Me.m_Obrigatorio = bolObrigatorio
        Me.m_MascaraInput = sMascaraInput
        Me.m_ValorDefault = strValorDefault
        Me.m_AtualizacaoEmMassa = bolAtualizacaoEmMassa
        Me.m_QuantidadeLinhas = lngQuantidadeLinhas
        Me.m_ListaOpcoes = strListaOpcoes
        Me.m_HabilitarBusca = blnHabilitarBusca

        If Me.m_HabilitarBusca Then
            Me.m_bBotaoBusca = CType(btbBotaoBusca, ButtonBuscaCarga)
        End If

    End Sub
End Class

Public Class DropDownListCargaTemplateField
    Implements ITemplate

    Private m_colType As ListItemType
    Private m_sColumnName As String
    Private m_sEditColumnName As String
    Private m_sColumnHeader As String
    Private m_Width As Integer = 0
    Private m_CssClass As String = String.Empty
    Private m_AlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private m_AlinhametoVertical As VerticalAlign = VerticalAlign.Middle
    Private strMetodoCargaListaOpcoes As String = String.Empty
    Private strCampoValorCargaListaOpcoes As String = String.Empty
    Private strCampoTextoCargaListaOpcoes As String = String.Empty
    Private strDataTableCargaListaOpcoes As String = String.Empty
    Private m_FormatoApresentacao As String = String.Empty
    Private m_ListaOpcoes As String = String.Empty
    Private bolObrigatorio As Boolean = False
    Private m_TipoValor As eTipoValor = eTipoValor.Texto
    Private m_AtualizacaoEmMassa As Boolean

    Public ReadOnly Property NomeColuna() As String
        Get
            Return Me.m_sColumnName
        End Get
    End Property

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Try

            Select Case m_colType
                Case ListItemType.Footer

                Case ListItemType.Header

                    Dim objLabel As New Label
                    With objLabel
                        .Text = Me.m_sColumnHeader
                    End With


                    If m_CssClass <> String.Empty Then
                        objLabel.CssClass = m_CssClass
                    End If

                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)


                Case ListItemType.Item, ListItemType.AlternatingItem


                    If Not Me.m_AtualizacaoEmMassa Then
                        Dim objLabel As New Label

                        With objLabel
                            .ID = "lbl" & m_sColumnName
                        End With

                        If m_CssClass <> String.Empty Then
                            objLabel.CssClass = m_CssClass
                        End If

                        CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                        AddHandler container.DataBinding, AddressOf Item_DataBinding

                        container.Controls.Add(objLabel)


                    Else

                        Dim objDDL As New DropDownListCarga

                        Dim strNomeColuna As String = Me.m_sColumnName

                        If Me.m_sEditColumnName.Trim <> String.Empty Then
                            strNomeColuna = m_sEditColumnName
                        End If

                        objDDL.ID = "" & strNomeColuna

                        If m_CssClass <> String.Empty Then
                            objDDL.CssClass = m_CssClass
                        End If

                        CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                        objDDL.Obrigatorio = Me.bolObrigatorio
                        objDDL.MetodoCargaListaOpcoes = Me.strMetodoCargaListaOpcoes
                        objDDL.DataTableCargaListaOpcoes = Me.strDataTableCargaListaOpcoes
                        objDDL.CampoValor = Me.strCampoValorCargaListaOpcoes
                        objDDL.CampoTexto = Me.strCampoTextoCargaListaOpcoes
                        objDDL.Width = Unit.Pixel(Me.m_Width)
                        objDDL.TipoValor = Me.m_TipoValor

                        If Me.m_ListaOpcoes.Split(";").Length > 0 Then

                            For Each strItem As String In Me.m_ListaOpcoes.Split(";")

                                Dim arrItem() As String
                                arrItem = strItem.Split(",")
                                If arrItem.Length = 2 Then

                                    objDDL.Itens.Add(New ItemCarga(arrItem(1), arrItem(0), False))

                                End If

                            Next
                        End If

                        AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                        container.Controls.Add(objDDL)

                    End If
                Case ListItemType.EditItem

                    Dim objDDL As New DropDownListCarga

                    Dim strNomeColuna As String = Me.m_sColumnName

                    If Me.m_sEditColumnName.Trim <> String.Empty Then
                        strNomeColuna = m_sEditColumnName
                    End If

                    objDDL.ID = "" & strNomeColuna

                    If m_CssClass <> String.Empty Then
                        objDDL.CssClass = m_CssClass
                    End If

                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                    objDDL.Obrigatorio = Me.bolObrigatorio
                    objDDL.MetodoCargaListaOpcoes = Me.strMetodoCargaListaOpcoes
                    objDDL.DataTableCargaListaOpcoes = Me.strDataTableCargaListaOpcoes
                    objDDL.CampoValor = Me.strCampoValorCargaListaOpcoes
                    objDDL.CampoTexto = Me.strCampoTextoCargaListaOpcoes
                    objDDL.Width = Unit.Pixel(Me.m_Width)
                    objDDL.TipoValor = Me.m_TipoValor

                    If Me.m_ListaOpcoes.Split(";").Length > 0 Then

                        For Each strItem As String In Me.m_ListaOpcoes.Split(";")

                            Dim arrItem() As String
                            arrItem = strItem.Split(",")
                            If arrItem.Length = 2 Then

                                objDDL.Itens.Add(New ItemCarga(arrItem(1), arrItem(0), False))

                            End If

                        Next
                    End If

                    AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                    container.Controls.Add(objDDL)

                Case ListItemType.Pager

                Case ListItemType.SelectedItem

                Case ListItemType.Separator


            End Select

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As String = ""

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

            item1Value = DataBinder.Eval(ri.DataItem, Me.m_sColumnName)

            Dim lbl As Label = FieldCell.Controls(0)

            If Me.m_ListaOpcoes.Split(";").Length > 1 Then

                For Each strItem As String In Me.m_ListaOpcoes.Split(";")

                    Dim arrItem() As String
                    arrItem = strItem.Split(",")
                    If arrItem.Length = 2 Then

                        If arrItem(0) = item1Value Then
                            lbl.Text = arrItem(1)
                            Exit For
                        End If

                    End If

                Next

            Else

                lbl.Text = Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao)

            End If

        End If


    End Sub

    Private Sub EditItem_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim objDDL As DropDownListCarga = FieldCell.Controls(0)

        Dim strNomeColuna As String = Me.m_sColumnName

        If Me.m_sEditColumnName.Trim <> String.Empty Then
            strNomeColuna = m_sEditColumnName
        End If

        Dim item1Value As String = String.Empty

        objDDL.AtualizarItens()

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, strNomeColuna)) Then

            item1Value = DataBinder.Eval(ri.DataItem, strNomeColuna)

            objDDL.ValorSelecionado = item1Value

        End If

        objDDL.Enabled = True

        If ri.Cells.GetCellIndex(FieldCell) = 0 Then

            CType(FieldCell.Page, MDP.Framework.Componentes.Page).SetFocus(objDDL)

        End If


    End Sub

    Public Sub New(ByVal objType As ListItemType, ByVal sColumnHeader As String, _
                   ByVal sColumnName As String, ByVal sEditColumnName As String, _
                   ByVal intTipoValor As eTipoValor, _
                   ByVal sMetodoCargaListaOpcoes As String, _
                   ByVal sListaOpcoes As String, _
                   ByVal sDataTableCargaListaOpcoes As String, _
                   ByVal sCampoValorCargaListaOpcoes As String, ByVal sCampoTextoCargaListaOpcoes As String, _
                   ByVal iWidth As Integer, ByVal sCssClass As String, _
                   ByVal haAlinhamentoHorizontal As HorizontalAlign, _
                   ByVal vaAlinhamentoVertical As VerticalAlign, _
                   ByVal sFormatoApresentacao As String, Optional ByVal bolObrigatorio As Boolean = True)

        m_colType = objType
        m_sColumnHeader = sColumnHeader
        m_sColumnName = sColumnName
        Me.m_sEditColumnName = sEditColumnName
        m_Width = iWidth
        m_CssClass = sCssClass
        Me.m_AlinhamentoHorizontal = haAlinhamentoHorizontal
        Me.m_AlinhametoVertical = vaAlinhamentoVertical
        Me.strMetodoCargaListaOpcoes = sMetodoCargaListaOpcoes
        Me.strDataTableCargaListaOpcoes = sDataTableCargaListaOpcoes
        Me.strCampoValorCargaListaOpcoes = sCampoValorCargaListaOpcoes
        Me.strCampoTextoCargaListaOpcoes = sCampoTextoCargaListaOpcoes
        Me.m_FormatoApresentacao = sFormatoApresentacao
        Me.m_ListaOpcoes = sListaOpcoes
        Me.bolObrigatorio = bolObrigatorio
        Me.m_TipoValor = intTipoValor


    End Sub
End Class

Public Class BotaoComandoTemplateField
    Implements ITemplate

    Private m_colType As ListItemType
    Private m_sColumnName As String
    Private m_sColumnHeader As String
    Private m_CssClass As String = String.Empty
    Private m_CssImgEditar As String = String.Empty
    Private m_CssImgExcluir As String = String.Empty
    Private m_CssImgConfirmar As String = String.Empty
    Private m_CssImgCancelar As String = String.Empty
    Private m_AlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private m_AlinhametoVertical As VerticalAlign = VerticalAlign.Middle
    Private bolPermiteAlteracao, bolPermiteExclusao As Boolean
    Private pg As Page

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Try

            Select Case m_colType
                Case ListItemType.Footer

                Case ListItemType.Header

                    Dim objLabel As New Label
                    With objLabel
                        .Text = Me.m_sColumnHeader
                    End With


                Case ListItemType.Item, ListItemType.AlternatingItem

                    CType(container, DataControlFieldCell).Width = Unit.Pixel(70)

                    Dim btnEditar As New ImageButton

                    btnEditar.ToolTip = "Editar"
                    btnEditar.ID = "btnEditar"
                    btnEditar.CommandName = "Editar"
                    btnEditar.ImageUrl = "~/imagens/pixel.gif"
                    btnEditar.CssClass = Me.m_CssImgEditar

                    Dim btnExcluir As New ImageButton

                    btnExcluir.ToolTip = "Excluir"
                    btnExcluir.ID = "btnExcluir"
                    btnExcluir.CommandName = "Excluir"
                    btnExcluir.ImageUrl = "~/imagens/pixel.gif"
                    btnExcluir.CssClass = Me.m_CssImgExcluir


                    btnEditar.Visible = bolPermiteAlteracao

                    container.Controls.Add(btnEditar)

                    Dim lit As New HtmlControls.HtmlGenericControl

                    lit.InnerHtml = "&nbsp;&nbsp;"

                    container.Controls.Add(lit)

                    container.Controls.Add(btnExcluir)

                    btnExcluir.Visible = bolPermiteExclusao

                    AddHandler container.DataBinding, AddressOf Item_DataBinding

                Case ListItemType.EditItem

                    CType(container, DataControlFieldCell).Width = Unit.Pixel(70)
                    Dim btnConfirmar As New ImageButton
                    Dim btnCancelar As New ImageButton

                    btnConfirmar.ToolTip = "Confirmar"
                    btnConfirmar.ID = "btnConfirmar"
                    btnConfirmar.CommandName = "Confirmar"
                    btnConfirmar.ImageUrl = "~/imagens/pixel.gif"
                    btnConfirmar.CssClass = Me.m_CssImgConfirmar


                    btnCancelar.ToolTip = "Cancelar"
                    btnCancelar.ID = "btnCancelar"
                    btnCancelar.CommandName = "Cancelar"
                    btnCancelar.CausesValidation = False
                    btnCancelar.ImageUrl = "~/imagens/pixel.gif"
                    btnCancelar.CssClass = Me.m_CssImgCancelar



                    container.Controls.Add(btnConfirmar)

                    Dim lit As New HtmlControls.HtmlGenericControl

                    lit.InnerHtml = "&nbsp;&nbsp;"

                    container.Controls.Add(lit)

                    container.Controls.Add(btnCancelar)

                    AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                Case ListItemType.Pager

                Case ListItemType.SelectedItem

                Case ListItemType.Separator


            End Select

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim btnEd As ImageButton = FieldCell.FindControl("btnEditar")

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical

        btnEd.CommandArgument = ri.DataItemIndex

        Dim btnExcluir As ImageButton = FieldCell.FindControl("btnExcluir")

        btnExcluir.CommandArgument = ri.DataItemIndex


    End Sub


    Private Sub EditItem_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical
        Dim btnConfirmar As ImageButton = FieldCell.FindControl("btnConfirmar")

        btnConfirmar.CommandArgument = ri.DataItemIndex



    End Sub


    Public Sub New(ByVal objType As ListItemType, ByRef pg As Page, ByVal sColumnHeader As String, _
                   ByVal sColumnName As String, ByVal sCssClass As String, _
                   ByVal strCssbtnEditar As String, ByVal strCssbtnExcluir As String, _
                   ByVal strCssbtnConfirmar As String, ByVal strCssbtnCancelar As String, _
                   ByVal haAlinhamentoHorizontal As HorizontalAlign, _
                   ByVal vaAlinhamentoVertical As VerticalAlign, _
                   ByVal bolPermiteAlteracao As Boolean, ByVal bolPermiteExclusao As Boolean)

        Me.m_colType = objType
        Me.m_sColumnHeader = sColumnHeader
        Me.m_sColumnName = sColumnName
        Me.m_CssClass = sCssClass
        Me.m_CssImgCancelar = strCssbtnCancelar
        Me.m_CssImgConfirmar = strCssbtnConfirmar
        Me.m_CssImgEditar = strCssbtnEditar
        Me.m_CssImgExcluir = strCssbtnExcluir
        Me.m_AlinhamentoHorizontal = haAlinhamentoHorizontal
        Me.m_AlinhametoVertical = vaAlinhamentoVertical
        Me.bolPermiteAlteracao = bolPermiteAlteracao
        Me.bolPermiteExclusao = bolPermiteExclusao
        Me.pg = pg

    End Sub

End Class

Public Class UploadTemplateField
    Implements ITemplate

    Private m_colType As ListItemType
    Private m_sColumnName As String
    Private m_sEditColumnName As String = String.Empty
    Private m_sColumnHeader As String
    Private m_Width As Integer = 0
    Private m_CssClass As String = String.Empty
    Private m_TipoValor As eTipoValor = eTipoValor.Texto
    Private m_TamanhoMaximo As Integer
    Private m_AlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private m_AlinhametoVertical As VerticalAlign = VerticalAlign.Middle
    Private m_FormatoApresentacao As String
    Private m_Obrigatorio As Boolean = False
    Private m_sTextoFixo As String = String.Empty
    Private m_UrlVisualizacao As String = ""
    Private m_ColunaNomeArquivo As String = ""


    Public ReadOnly Property NomeColuna() As String
        Get
            Return Me.m_sColumnName
        End Get
    End Property

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Try

            Select Case m_colType

                Case ListItemType.Footer

                    Dim objLabel As New Label

                    With objLabel
                        .ID = "lblTotal" & m_sColumnName
                    End With

                    If m_CssClass <> String.Empty Then
                        objLabel.CssClass = m_CssClass
                        objLabel.Font.Bold = True
                    End If


                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)


                Case ListItemType.Header

                    Dim objLabel As New Label
                    With objLabel
                        .Text = Me.m_sColumnHeader
                    End With


                    If m_CssClass <> String.Empty Then
                        objLabel.CssClass = m_CssClass
                    End If


                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)


                Case ListItemType.Item, ListItemType.AlternatingItem


                    Dim lnkVisualizar As New HyperLink

                    With lnkVisualizar
                        .ID = "lnk" & m_sColumnName
                    End With

                    If m_CssClass <> String.Empty Then
                        lnkVisualizar.CssClass = m_CssClass
                    End If

                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                    AddHandler container.DataBinding, AddressOf Item_DataBinding

                    container.Controls.Add(lnkVisualizar)

                Case ListItemType.EditItem

                    Dim strNomeColuna As String = Me.m_sColumnName

                    If Me.m_sEditColumnName.Trim <> String.Empty Then
                        strNomeColuna = m_sEditColumnName
                    End If


                    Dim objUpload As New WebControls.FileUpload
                    objUpload.ID = "upl_" & strNomeColuna
                    objUpload.Attributes.Add("NomeArquivo", Me.m_ColunaNomeArquivo)

                    If m_CssClass <> String.Empty Then
                        objUpload.CssClass = m_CssClass
                    End If

                    'objUpload.Obrigatorio = m_Obrigatorio                    

                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                    objUpload.Width = Unit.Percentage(100)

                    AddHandler container.DataBinding, AddressOf EditItem_DataBinding
                    Dim chkLimpar As New CheckBox
                    chkLimpar.CssClass = m_CssClass
                    chkLimpar.Text = "Limpar"
                    chkLimpar.BorderStyle = BorderStyle.None

                    Dim tbl As New UI.WebControls.Table
                    tbl.CellPadding = 0
                    tbl.CellSpacing = 0
                    tbl.Rows.Add(New TableRow)
                    tbl.Rows(0).Cells.Add(New TableCell)
                    tbl.Rows(0).Cells.Add(New TableCell)

                    tbl.Rows(0).Cells(0).Controls.Add(objUpload)
                    tbl.Rows(0).Cells(0).Width = Unit.Pixel(200)
                    tbl.Rows(0).Cells(1).Controls.Add(chkLimpar)
                    container.Controls.Add(tbl)


                Case ListItemType.Pager

                Case ListItemType.SelectedItem

                Case ListItemType.Separator


            End Select

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As Object

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

            item1Value = DataBinder.Eval(ri.DataItem, Me.m_sColumnName)

            Dim lnk As HyperLink = FieldCell.Controls(0)

            If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

                item1Value = DataBinder.Eval(ri.DataItem, Me.m_sColumnName)

                If Me.m_sTextoFixo.Trim = String.Empty Then
                    lnk.Text = Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao)
                Else
                    lnk.Text = Me.m_sTextoFixo
                End If

            End If

            lnk.NavigateUrl = Me.m_UrlVisualizacao
            lnk.NavigateUrl = Me.m_UrlVisualizacao.Replace("{0}", Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao))

        End If


    End Sub

    Private Sub EditItem_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)




    End Sub

    Public Sub New(ByVal objType As ListItemType, ByVal sColumnHeader As String, _
                   ByVal sColumnName As String, ByVal sEditColumnName As String, ByVal intTipoValor As eTipoValor, _
                   ByVal numTamanhoMaximo As Integer, _
                   ByVal iWidth As Integer, ByVal sCssClass As String, _
                   ByVal haAlinhamentoHorizontal As HorizontalAlign, _
                   ByVal vaAlinhamentoVertical As VerticalAlign, _
                   ByVal sFormatoApresentacao As String, ByVal strUrlVisualizacao As String, _
                   ByVal sTextoFixo As String, _
                   ByVal sColunaNomeArquivo As String, _
                   ByVal bolObrigatorio As Boolean)

        m_colType = objType
        m_sColumnHeader = sColumnHeader
        m_sColumnName = sColumnName
        m_sEditColumnName = sEditColumnName
        Me.m_sTextoFixo = sTextoFixo
        m_Width = iWidth
        m_CssClass = sCssClass
        m_TipoValor = intTipoValor
        m_TamanhoMaximo = numTamanhoMaximo
        Me.m_AlinhamentoHorizontal = haAlinhamentoHorizontal
        Me.m_AlinhametoVertical = vaAlinhamentoVertical
        Me.m_FormatoApresentacao = sFormatoApresentacao
        Me.m_UrlVisualizacao = strUrlVisualizacao
        Me.m_Obrigatorio = bolObrigatorio
        Me.m_ColunaNomeArquivo = sColunaNomeArquivo


    End Sub
End Class

Public Class CheckBoxCargaTemplateField
    Implements ITemplate

    Private m_colType As ListItemType
    Private m_sColumnName As String
    Private m_sEditColumnName As String = String.Empty
    Private m_sColumnHeader As String
    Private m_Width As Integer = 0
    Private m_CssClass As String = String.Empty
    Private m_AlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private m_AlinhametoVertical As VerticalAlign = VerticalAlign.Middle
    Private bolObrigatorio As Boolean
    Private m_TipoValor As eTipoValor = eTipoValor.Logico
    Private m_ListaOpcoes As String = ""
    Private m_AtualizacaoEmMassa As Boolean
    Private m_FormatoApresentacao As String = String.Empty
    Private m_TamanhoMaximo As Integer
    Private m_Obrigatorio As Boolean = False
    Private m_MascaraInput As String = String.Empty
    Private m_ValorDefault As String = String.Empty
    Private m_HabilitarBusca As Boolean = False
    Private m_QuantidadeLinhas As Long = 1


    Public ReadOnly Property NomeColuna() As String
        Get
            Return Me.m_sColumnName
        End Get
    End Property

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Try

            Select Case m_colType
                Case ListItemType.Footer

                Case ListItemType.Header

                    Dim objLabel As New Label
                    With objLabel
                        .Text = Me.m_sColumnHeader
                    End With


                    If m_CssClass <> String.Empty Then
                        objLabel.CssClass = m_CssClass
                    End If

                    CType(container, DataControlFieldCell).HorizontalAlign = Me.m_AlinhamentoHorizontal
                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)
                    CType(container, DataControlFieldCell).Controls.Add(objLabel)


                Case ListItemType.Item, ListItemType.AlternatingItem


                    If Not Me.m_AtualizacaoEmMassa Then
                        Dim objLabel As New Label

                        With objLabel
                            .ID = "lbl" & m_sColumnName
                        End With

                        If m_CssClass <> String.Empty Then
                            objLabel.CssClass = m_CssClass
                        End If

                        CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                        AddHandler container.DataBinding, AddressOf Item_DataBinding

                        container.Controls.Add(objLabel)


                    Else

                        Dim objchk As New CheckBoxCarga

                        Dim strNomeColuna As String = Me.m_sColumnName

                        If Me.m_sEditColumnName.Trim <> String.Empty Then
                            strNomeColuna = m_sEditColumnName
                        End If

                        objchk.ID = "" & strNomeColuna

                        If m_CssClass <> String.Empty Then
                            objchk.CssClass = m_CssClass
                        End If

                        CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                        objchk.Obrigatorio = Me.bolObrigatorio
                        objchk.Width = Unit.Pixel(Me.m_Width)
                        objchk.TipoValor = Me.m_TipoValor

                        AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                        container.Controls.Add(objchk)

                    End If
                Case ListItemType.EditItem

                    Dim objchk As New CheckBoxCarga

                    Dim strNomeColuna As String = Me.m_sColumnName

                    If Me.m_sEditColumnName.Trim <> String.Empty Then
                        strNomeColuna = m_sEditColumnName
                    End If

                    objchk.ID = "" & strNomeColuna

                    If m_CssClass <> String.Empty Then
                        objchk.CssClass = m_CssClass
                    End If

                    CType(container, DataControlFieldCell).Width = Unit.Pixel(Me.m_Width)

                    objchk.Obrigatorio = Me.bolObrigatorio
                    objchk.Width = Unit.Pixel(Me.m_Width)
                    objchk.TipoValor = Me.m_TipoValor

                    AddHandler container.DataBinding, AddressOf EditItem_DataBinding

                    container.Controls.Add(objchk)

                Case ListItemType.Pager

                Case ListItemType.SelectedItem

                Case ListItemType.Separator


            End Select

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As String = ""

        FieldCell.HorizontalAlign = Me.m_AlinhamentoHorizontal
        FieldCell.VerticalAlign = Me.m_AlinhametoVertical

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, Me.m_sColumnName)) Then

            item1Value = DataBinder.Eval(ri.DataItem, Me.m_sColumnName)

            Dim lbl As Label = FieldCell.Controls(0)

            If Me.m_ListaOpcoes.Split(";").Length > 1 Then

                For Each strItem As String In Me.m_ListaOpcoes.Split(";")

                    Dim arrItem() As String
                    arrItem = strItem.Split(",")
                    If arrItem.Length = 2 Then

                        If arrItem(0) = item1Value Then
                            lbl.Text = arrItem(1)
                            Exit For
                        End If

                    End If

                Next

            Else

                lbl.Text = Diversos.FormatarValor(item1Value, Me.m_FormatoApresentacao)

            End If

        End If


    End Sub


    Private Sub EditItem_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim FieldCell As DataControlFieldCell = sender

        Dim ri As GridViewRow = FieldCell.NamingContainer

        Dim item1Value As String = String.Empty

        Dim strNomeColuna As String = Me.m_sColumnName

        If Me.m_sEditColumnName.Trim <> String.Empty Then
            strNomeColuna = m_sEditColumnName
        End If

        If Not IsDBNull(DataBinder.Eval(ri.DataItem, strNomeColuna)) Then
            item1Value = DataBinder.Eval(ri.DataItem, strNomeColuna)

        End If
        Dim chk As CheckBoxCarga
        If TypeOf FieldCell.Controls(0) Is HtmlControls.HtmlTable Then
            chk = CType(FieldCell.Controls(0), HtmlControls.HtmlTable).Rows(0).Cells(0).Controls(0)
        Else
            chk = FieldCell.Controls(0)
        End If

        chk.Enabled = True
        chk.ValorSelecionado = item1Value

        If ri.Cells.GetCellIndex(FieldCell) = 0 Then

            CType(FieldCell.Page, Mdp.Framework.Componentes.Page).SetFocus(chk)

        End If

    End Sub


    Public Sub New(ByVal objType As ListItemType, ByVal sColumnHeader As String, _
                   ByVal sColumnName As String, ByVal sEditColumnName As String, ByVal intTipoValor As eTipoValor, _
                   ByVal numTamanhoMaximo As Integer, _
                   ByVal iWidth As Integer, ByVal sCssClass As String, _
                   ByVal haAlinhamentoHorizontal As HorizontalAlign, _
                   ByVal vaAlinhamentoVertical As VerticalAlign, _
                   ByVal sFormatoApresentacao As String, ByVal sMascaraInput As String, _
                   ByVal bolObrigatorio As Boolean, ByVal strValorDefault As String, _
                   ByVal lngQuantidadeLinhas As Long, _
                   Optional ByVal bolAtualizacaoEmMassa As Boolean = False, _
                   Optional ByVal strListaOpcoes As String = "", _
    Optional ByVal blnHabilitarBusca As Boolean = False)

        m_colType = objType
        m_sColumnHeader = sColumnHeader
        m_sColumnName = sColumnName
        m_sEditColumnName = sEditColumnName
        m_Width = iWidth
        m_CssClass = sCssClass
        m_TipoValor = intTipoValor
        m_TamanhoMaximo = numTamanhoMaximo
        Me.m_AlinhamentoHorizontal = haAlinhamentoHorizontal
        Me.m_AlinhametoVertical = vaAlinhamentoVertical
        Me.m_FormatoApresentacao = sFormatoApresentacao
        Me.m_Obrigatorio = bolObrigatorio
        Me.m_MascaraInput = sMascaraInput
        Me.m_ValorDefault = strValorDefault
        Me.m_AtualizacaoEmMassa = bolAtualizacaoEmMassa
        Me.m_QuantidadeLinhas = lngQuantidadeLinhas
        Me.m_ListaOpcoes = strListaOpcoes
        Me.m_HabilitarBusca = blnHabilitarBusca


    End Sub
End Class